import pLimit from 'p-limit'

/**
 * 获取并行数
 * @param {number} total
 */
const getConcurrencyNum = (total) => {
  for (let i = 1; i <= 10; i++) {
    const num = i * 10
    if (total <= num * num) {
      return Math.ceil(total / num)
    }
  }
  return 100
}

export const getPLimit = total => {
  const concurrency = getConcurrencyNum(total);
  return pLimit(concurrency);
}